﻿using DLL.Standard.Infrastructure;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DLL.NET60.DB.MS.Entity.DTO
{
    [Serializable]
    public class DTO_adi_FlushGroup : CNotifyPropertyChanged, ICloneable
    {
        private string _DrugFlushGroupCode = "";
        private string _Drug_UniqueCode = "";
        private int _FlushGroupID = 0;
        private int _FlushLoopCount = 1;
        private int _PumpBackLoopCount = 0;

        [Key]
        [StringLength(255)]
        public string DrugFlushGroupCode
        { get { return _DrugFlushGroupCode; } set { _DrugFlushGroupCode = value; this.OnPropertyChanged(); } }

        [StringLength(255)]
        public string Drug_UniqueCode
        { get { return _Drug_UniqueCode; } set { _Drug_UniqueCode = value; this.OnPropertyChanged(); } }

        public int FlushGroupID
        { get { return _FlushGroupID; } set { _FlushGroupID = value; this.OnPropertyChanged(); } }

        public int FlushLoopCount
        { get { return _FlushLoopCount; } set { _FlushLoopCount = value; this.OnPropertyChanged(); } }

        public int PumpBackLoopCount
        { get { return _PumpBackLoopCount; } set { _PumpBackLoopCount = value; this.OnPropertyChanged(); } }

        public virtual DTO_adi_dic_drug drug { get; set; }
        private List<DTO_adi_FlushParam> _flush_Params = new List<DTO_adi_FlushParam>();

        public virtual List<DTO_adi_FlushParam> flush_Params
        {
            get { return _flush_Params; }
            set { _flush_Params = value; this.OnPropertyChanged(); }
        }

        private List<DTO_adi_PumpBackParam> _PumpBack_Params = new List<DTO_adi_PumpBackParam>();

        public virtual List<DTO_adi_PumpBackParam> pumpBack_Params
        {
            get { return _PumpBack_Params; }
            set { _PumpBack_Params = value; this.OnPropertyChanged(); }
        }

        public void SetFlushParamUniqueCode(string drugUniqueCode)
        {
            Drug_UniqueCode = drugUniqueCode;
            if (flush_Params.Count > 0)
            {
                int count = flush_Params.Count;
                for (int i = 0; i < count; i++)
                {
                    flush_Params[i].DrugFlushGroupCode = Drug_UniqueCode;
                    flush_Params[i].DrugFlushParamCode = Drug_UniqueCode + "-" + flush_Params[i].LoopIndex.ToString();
                }
            }
            if (pumpBack_Params.Count > 0)
            {
                int count = pumpBack_Params.Count;
                for (int i = 0; i < count; i++)
                {
                    pumpBack_Params[i].DrugFlushGroupCode = Drug_UniqueCode;
                    pumpBack_Params[i].DrugPumpBackCode = Drug_UniqueCode + "-" + pumpBack_Params[i].LoopIndex.ToString();
                }
            }
        }

        public void InitializeFlushParam()
        {
            flush_Params.Clear();
            for (int i = 0; i < 6; i++)
            {
                DTO_adi_FlushParam fp = new DTO_adi_FlushParam();
                fp.LoopIndex = i;
                fp.DrugFlushGroupCode = DrugFlushGroupCode;
                fp.DrugFlushParamCode = DrugFlushGroupCode + "-" + i.ToString();
                flush_Params.Add(fp);
            }
            pumpBack_Params.Clear();
            for (int i = 0; i < 3; i++)
            {
                DTO_adi_PumpBackParam pbp = new DTO_adi_PumpBackParam();
                pbp.LoopIndex = i;
                pbp.DrugFlushGroupCode = DrugFlushGroupCode;
                pbp.DrugPumpBackCode = DrugFlushGroupCode + "-" + i.ToString();
                pumpBack_Params.Add(pbp);
            }
        }

        public object Clone()
        {
            DTO_adi_FlushGroup fg = new DTO_adi_FlushGroup();
            fg.DrugFlushGroupCode = this.DrugFlushGroupCode;
            fg.Drug_UniqueCode = this.Drug_UniqueCode;
            fg.FlushGroupID = this.FlushGroupID;
            fg.FlushLoopCount = this.FlushLoopCount;
            fg.PumpBackLoopCount = this.PumpBackLoopCount;
            int count = this.flush_Params.Count();
            for (int i = 0; i < count; i++)
            {
                fg.flush_Params.Add((DTO_adi_FlushParam)this.flush_Params[i].Clone());
            }
            int pcount = this.pumpBack_Params.Count();
            for (int i = 0; i < pcount; i++)
            {
                fg.pumpBack_Params.Add((DTO_adi_PumpBackParam)this.pumpBack_Params[i].Clone());
            }
            return fg;
        }
    }
}